<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%request.setCharacterEncoding("utf-8"); %>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>SL会员商城主页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
	<link rel="shortcut icon" href="img/SL.ico" type="image/x-icon">
    <link href="<%=basePath %>css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="<%=basePath %>css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- Morris -->
    <link href="<%=basePath %>css/plugins/morris/morris-0.4.3.min.css" rel="stylesheet">

    <!-- Gritter -->
    <link href="<%=basePath %>js/plugins/gritter/jquery.gritter.css" rel="stylesheet">

    <link href="<%=basePath %>css/animate.css" rel="stylesheet">
    <link href="<%=basePath %>css/style.css?v=4.1.0" rel="stylesheet">
	<!--jquery.min.js-->
	<script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-success pull-right">月</span>
                        <h5>平均月销总量</h5>
                    </div>
                    <div class="ibox-content">
                        <h1 id="monthSales" class="no-margins"></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-info pull-right">月</span>
                        <h5>平均月总收入</h5>
                    </div>
                    <div class="ibox-content">
                        <h1 id="monthIncome" class="no-margins"></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-primary pull-right">年</span>
                        <h5>年总销量</h5>
                    </div>
                    <div class="ibox-content">
                        <h1 id="yearSales" class="no-margins"></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <span class="label label-danger pull-right">年</span>
                        <h5>年总收入</h5>
                    </div>
                    <div class="ibox-content">
                        <h1 id="yearIncome" class="no-margins"></h1>
                    </div>
                </div>
            </div>
            </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商品销售情况</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-9">
                                <div class="flot-chart">
                                    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    								<div id="main" style="width: 1080;height:200px;"></div>
                                </div>
                            </div>
                            <div class="col-sm-3">销量前四
                            <br />
                           
                                <ul class="stat-list">
                                    <li>
                                        <h2 class="no-margins" id="maxName" style="font-size:16px"></h2>
                                        <div class="stat-percent" id="maxSales" style="margin-top:-2px"></div>
                                        <span class="badge" id="max"></span>
                                        <div class="progress progress-mini">
                                            <div style="" id="maxPr" class="progress-bar"></div>
                                        </div>
                                    </li>
                                    <li>
                                        <h2 class="no-margins "  id="secondName" style="font-size:16px"></h2>
                                        <div class="stat-percent"  id="secondSales" style="margin-top:-2px"></div>
                                        <span class="badge" id="second"></span>
                                        <div class="progress progress-mini">
                                            <div style="" id="secondPr" class="progress-bar"></div>
                                        </div>
                                    </li>
                                    <li>
                                        <h2 class="no-margins " id="thirdName" style="font-size:16px"></h2>
                                        <div class="stat-percent"  id="thirdSales" style="margin-top:-2px"></div>
                                        <span class="badge" id="third"></span>
                                        <div class="progress progress-mini">
                                            <div style="" id="thirdPr"  class="progress-bar"></div>
                                        </div>
                                    </li>
                                    <li>
                                        <h2 class="no-margins " id="fourthName" style="font-size:16px"></h2>
                                        <div class="stat-percent" id="fourthSales" style="margin-top:-2px"></div>
                                        <span class="badge" id="fourth"></span>
                                        <div class="progress progress-mini">
                                            <div style="" id="fourthPr" class="progress-bar"></div>
                                        </div>
                                    </li>
                                    </ul>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="<%=basePath %>js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=basePath %>js/bootstrap.min.js?v=3.3.6"></script>



    <!-- Flot -->
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.js"></script>
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.tooltip.min.js"></script>
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.spline.js"></script>
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.resize.js"></script>
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.pie.js"></script>
    <script src="<%=basePath %>js/plugins/flot/jquery.flot.symbol.js"></script>

    <!-- Peity -->
    <script src="<%=basePath %>js/plugins/peity/jquery.peity.min.js"></script>
    <script src="<%=basePath %>js/demo/peity-demo.js"></script>

    <!-- 自定义js -->
    <script src="<%=basePath %>js/content.js?v=1.0.0"></script>


    <!-- jQuery UI -->
    <script src="<%=basePath %>js/plugins/jquery-ui/jquery-ui.min.js"></script>

    <!-- Jvectormap -->
    <script src="<%=basePath %>js/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
    <script src="<%=basePath %>js/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>

    <!-- EayPIE -->
    <script src="<%=basePath %>js/plugins/easypiechart/jquery.easypiechart.js"></script>

    <!-- Sparkline -->
    <script src="<%=basePath %>js/plugins/sparkline/jquery.sparkline.min.js"></script>

    <!-- Sparkline demo data  -->
    <script src="<%=basePath %>js/demo/sparkline-demo.js"></script>
	<!-- echarts.common.min.js -->
	<script src="${pageContext.request.contextPath}/js/plugins/echarts/echarts.common.min.js"></script>

</body>
<script>
	
	$.get('${pageContext.request.contextPath}/MainServlet',function(data){
		var goodsSales = JSON.parse(data);
		$('#monthSales').html(goodsSales[0][0].monthGoodsSales+'件');
		$('#monthIncome').html(goodsSales[0][0].monthGoodsPrice+'元');
		$('#yearSales').html(goodsSales[0][0].yearGoodsSales+'件');
		$('#yearIncome').html(goodsSales[0][0].yearGoodsPrice+'元');
		$('#maxName').html(goodsSales[0][1].goods_name);
		$('#maxSales').html(goodsSales[0][1].xiaoliang);
		$('#secondName').html(goodsSales[0][2].goods_name);
		$('#secondSales').html(goodsSales[0][2].xiaoliang);
		
		$('#thirdName').html(goodsSales[0][3].goods_name);
		$('#thirdSales').html(goodsSales[0][3].xiaoliang);
		
		$('#fourthName').html(goodsSales[0][4].goods_name);
		$('#fourthSales').html(goodsSales[0][4].xiaoliang);
		
	 	var maxPr = goodsSales[0][1].xiaoliang/goodsSales[0][0].yearGoodsSales*100+'%';
	 	$('#maxPr').css("width",maxPr);
	 	var secondPr = goodsSales[0][2].xiaoliang/goodsSales[0][0].yearGoodsSales*100+'%';
	 	$('#secondPr').css("width",secondPr);
	 	var thirdPr = goodsSales[0][3].xiaoliang/goodsSales[0][0].yearGoodsSales*100+'%';
	 	$('#thirdPr').css("width",thirdPr);
	 	var fourthPr = goodsSales[0][4].xiaoliang/goodsSales[0][0].yearGoodsSales*100+'%';
	 	$('#fourthPr').css("width",fourthPr);
	 	var one = maxPr.substring(0,4)+'%';
		$('#max').html(one);
		var two = secondPr.substring(0,4)+'%';
		$('#second').html(two);
		var three = thirdPr.substr(0,4)+'%';
		$('#third').html(three);
		var four = fourthPr.substring(0,4)+'%';
		$('#fourth').html(four);
	});
	  
	//基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('main'));
    $.get('${pageContext.request.contextPath}/MainServlet',function (data) { 
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: ''
            },
            tooltip: {
                trigger: 'axis'
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                show: true,
                feature: {
                    saveAsImage: {},
                    magicType: {
                        type: ['bar','line']
                    },
                    restore:{}
                }
            },
            legend: {
                data: data[1]
            },
            xAxis: {
            	 type:'category',
                data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
                axisLabel:{
                    interval:0
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    formatter: '{value}'
                }
            },
            series: data[2]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option,true);
    },'json');
</script>
</html>
